#include "common.hpp"


namespace common {

using namespace std;


string repr(nullptr_t) {return string("'()");}
string repr(const int& x) {return to_string(x);}
string repr(const double& d) {return to_string(d);}
string repr(const string& s) {return quoted(std::move(s));}
string repr(const char* s){return repr(string(s));}
string quoted(const string& in)
{
    stringstream ss;
    string out;
    ss<<std::quoted(in);
    using std::operator>>;
    ss >> out;
    return out;
}


std::size_t replace_all(std::string& inout, std::string_view what, std::string_view with)
{
    std::size_t count{};
    for (std::string::size_type pos{};
         inout.npos != (pos = inout.find(what.data(), pos, what.length()));
         pos += with.length(), ++count) {
        inout.replace(pos, what.length(), with.data(), with.length());
    }
    return count;
}

string indent(const string& in, int n)
{
    const string spaces = string(n, ' ');
    string s = in;
    replace_all(s, "\n", string("\n") + spaces);
    s = spaces + s;
    return s;
}


}
